<?php

namespace App\Http\Controllers\H5;

use App\Aliyun\dysms\SmsSender;
use App\Models\Verify;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class SmsController extends Controller
{

    public function getCode(Request $request)
    {
        $phone = $request->input('phone');

        if ($phone) {
            $code = rand(100, 999).rand(100, 999);
            $sender = new SmsSender();
            $sender->setPhoneNumbers($phone)
                ->setTemplateCode('SMS_149650022')
                ->setTemplateParam(['code'=>$code])
                ->send();
            Verify::insert([
                'phone'=>$phone,
                'code'=>$code,
                'created_at'=>time()
            ]);
        }

        return ajaxReturn();
    }
}
